Many of us have seen films containing remarkably realistic dinosaurs, aliens, animated toys and other fanciful creatures. Such animations are made possible by computer graphics. Using such techniques, a computer graphics artist can specify how each object should look and how it should change in appearance over time, and a computer then models the objects and displays them on a display such as your television or a computer screen. The computer takes care of performing the many tasks required to make sure that each part of the displayed image is colored and shaped just right based on the position and orientation of each object in a scene, the direction in which light seems to strike each object, the surface texture of each object, and other factors.
Because computer graphics generation is complex, computer-generated three-dimensional graphics just a few years ago were mostly limited to expensive specialized flight simulators, high-end graphics workstations and supercomputers. The public saw some of the images generated by these computer systems in movies and expensive television advertisements, but most of us couldn't actually interact with the computers doing the graphics generation. All this has changed with the availability of relatively inexpensive 3D graphics platforms such as, for example, the Nintendo 64® and various 3D graphics cards now available for personal computers. It is now possible to interact with exciting 3D animations and simulations on relatively inexpensive computer graphics systems in your home or office.
Most computer graphics research has tended to focus on producing realistic images. This research has been very successful. Computers can now generate images that are so realistic that you can't tell them apart from photographs. For example, many of us have seen very convincing dinosaurs, aliens and other photorealistic computer-generated special effects in movie and television. New pilots train on computer-based flight simulators so realistic that they nearly duplicate actual flying. Low-cost home video game systems can now provide a remarkable degree of realism, giving the game player an illusion of driving a real race car along a track, skiing down a snow and ice covered ski slope, walking through a medieval castle, or the like. For most games, this illusion of realism significantly enhances the game play experience.
One way to enhance realism is to model the opacity (transparency) of surfaces using a technique called “alpha blending.” Using this conventional technique, each image element is assigned an “alpha value” representing its degree of opacity. The colors of the image element are blended based on the alpha value—allowing one object to appear to be visible through another object. A further conventional technique called “alpha function” or “alpha test” can be used to discard an object fragment based on comparing the fragment's alpha value with a reference function or value. Alpha test may decide to not blend (i.e., to throw away) a potential part of an image because it is transparent and will therefore be invisible.
Alpha blending and alpha test are especially useful for modeling transparent objects such as water and glass. This same functionality can also be used with texture mapping to achieve a variety of effects. For example, the alpha test is frequently used to draw complicated geometry using texture maps on polygons—with the alpha component acting as a matte. By way of illustration, a tree can be drawn as a picture (texture) of a tree on a polygon. The tree parts of the texture image can have an alpha value of 1 (opaque), and the non-tree parts can have an alpha value of 0 (transparent). In this way, the “non-tree” parts of the polygons are mapped to invisible (transparent) portions of the texture map, while the “tree” portions of the polygon are mapped to visible (opaque) portions of the texture map.
The alpha component of a texture can be used in other ways—for example, to cut holes or trim surfaces. As one example, an image of a cutout or a trim region can be stored in a texture map. When mapping the texture to the polygon surface, alpha testing or blending can be used to cut the cutout or trimmed region out of the polygon's surface. Additionally, the alpha channel of a computer graphics system can be also be used to provide non-photorealistic image effects such as cartoon outlining. An arrangement described in U.S. patent application Ser. No. 09/468,109 filed Dec. 21, 1999 uses the alpha channel of a real time rendering system to encode identifications corresponding to different objects or portions of objects. The system renders the objects into a color frame buffer, and writes corresponding object Ids into an alpha frame buffer. An alpha test operation is performed on the alpha frame buffer, and the alpha compare results (i.e., the absolute value of the difference between two alpha values) are used to selectively blend outline coloration around silhouette and other edges defined between image areas encoded with different alpha/Ids.
Typical generally available 3D graphics application programmer interfaces such as DirectX and OpenGL support alpha compares for transparency or other purposes, e.g., to compare an iterated or texture alpha to a constant and “kill” the pixel in the compare fails. As one example, Direct3D provides a command “D3DRENDERSTATE_ALPHATEST-ENABLE that can be used to enable alpha testing. The command D3DCOMFUNC enumerated type allows the programmer to specify the possible tests used in the alpha compare operation (e.g., never, always, <, >, less than or equal to, greater than or equal to, not equal to, etc.) For example, if the alpha comparison function is set to “greater than or equal to”, then if the pixel being rasterized is less opaque than the color already at the pixel, Direct3D will skip it completely—saving the time that would have been required to blend the two colors together and preventing the color and z buffers from being updated. It is also possible to compare the incoming alpha with a programmer-specified reference alpha value (e.g., “if (alpha<128/255) then kill the pixel) by using the D3DRENDERSTATE_ALPHAREF command. See, e.g., Kovach, Inside Direct3D (Microsoft 2000) at 289–291. Similar alpha testing/comparison capabilities are provided in OpenGL by the GL_ALPHA_TEST, GL_ALPHA_TEST_FUNC and GL_ALPHA_TEST_REF commands. See, e.g., Neider et al, OpenGL Programming Guide (Addison-Wesley 1993) at 301–302.
An issue that arises when implementing various complex alpha comparisons including but not limited to the cartoon outlining algorithm mentioned above, is how to efficiently perform more complicated alpha comparisons in hardware using a single rendering pass. For example, while arbitrarily complex alpha tests can typically be straightforwardly be performed by a processor executing software, it may be desirable (e.g., for increased speed performance) to use a hardware-based alpha test. Such an arbitrarily complex alpha test capability has not generally been available in the past within the context of a low cost graphics system such as a home video game or a personal computer graphics card.
The present invention solves this problem by providing a hardware-based pixel shader capable of performing plural alpha comparisons that can be logically combined to achieve a wide range of alpha test functionality. In accordance with one aspect of the invention, the pixel shader can be used to provide a transparency tree analogous to a shade tree. In particular, alpha functionality can be used to provide N logical alpha operations on M alpha inputs, where N and M can be any integers.
One aspect of the invention provides a method of generating a graphics image comprising generating information representing a surface to be imaged, said information including alpha; performing, within the same rendering pass, plural alpha comparisons on said alpha information to provide corresponding plural alpha comparison results; logically combining said plural alpha comparison results; and rendering said graphics image based at least in part on said logical combination. The rendering step may include selecting whether or not to kill a pixel based on said logical combination. The performing step can be performed in hardware and/or using a recirculating shader.
In accordance with a further aspect provided by the invention, a graphics system comprises a texture unit including a texture coordinate matrix multiplier; a shader including an alpha channel; an embedded frame buffer that can store an alpha image; and a copy-out pipeline for copying an alpha image from said frame buffer for use as a texture by said texture unit, wherein said graphics system performs plural alpha comparisons in a single rendering pass.
The combination of alpha compares and alpha logical operations can be used for a wide range of additional alpha-based effects. For example, dual alpha comparisons can be used to provide non-photorealistic effects such as cartoon outlining (e.g., to efficiently determine whether to blend a cartoon outline color based on said logical combination by implementing an absolute value function).